package com.cs.controller;

import com.cs.domain.CSCategory;
import com.cs.domain.CSFramePlan;
import com.cs.domain.vo.CSSupplierVO;
import com.cs.domain.vo.FrameLineVO;
import com.cs.service.CSFramePlanService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresLogin;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author：bbdf
 * @Package：com.cs.controller
 * @Project：RuoYi-Cloud
 * @name：CSFramePlanController
 * @Date：2024-11-19 16:48
 * @Filename：CSFramePlanController
 */
@Tag(name = "管理后台 - 框架采购计划")
@RestController
@RequestMapping("/frameworkPlan")
public class CSFramePlanController extends BaseController {

    @Autowired
    private CSFramePlanService csFramePlanService;

    /**
     * 获得框架采购计划列表(分页)
     */
    @GetMapping("/getFrameworkPlan")
    public TableDataInfo getFrameworkPlan(CSFramePlan plan){
        startPage();
        List<CSFramePlan> frameworkPlan = csFramePlanService.getFrameworkPlan(plan);
        return getDataTable(frameworkPlan);
    }

    /**
     * 跟进框架计划编码查询详细信息
     */
    @GetMapping("/getFrameworkPlanDetails/{planCode}")
    public  Map getFrameworkPlanDetails (@PathVariable String planCode){
        return csFramePlanService.getFrameworkPlanDetails(planCode);
    }


    /**
     * 新增采购计划框架
     */
    @RequiresLogin
    @PostMapping("/addFrameworkPlan")
    public Integer addFrameworkPlan(@RequestBody FrameLineVO frameLineVO){
        return csFramePlanService.addFrameworkPlan(frameLineVO);
    }

    /**
     * 编辑采购框架前获得信息
     */
    @GetMapping("/getFramePlanByPlanCode/{planCode}")
    public Map<String,Object> getFramePlanByPlanCode(@PathVariable String planCode){
        return csFramePlanService.getFramePlanByPlanCode(planCode);
    }


    /**
     * 修改采购框架
     */
    @RequiresLogin
    @PutMapping("/editFramePlan")
    public R<Integer> editFramePlan(@RequestBody FrameLineVO frameLineVO){
        return csFramePlanService.editFramePlan(frameLineVO);
    }


    /**
     * 获得物料类别名称
     */
    @GetMapping("/getCSType")
    public R<List<CSCategory>> getCSType(){
        return csFramePlanService.getCSType();
    }

    /**
     * 根据框架计划编码更改状态
     */
    @RequiresLogin
    @PutMapping("/updateStatusByCode/{planCode}")
    public R<Integer> updateStatusByCode(@PathVariable String planCode){
        return csFramePlanService.updateStatusByCode(planCode);
    }


    /**
     * 根据框架计划编码更改状态
     */
    @RequiresLogin
    @PutMapping("/allowFrameworkPlan/{planCode}")
    public R<Integer> allowFrameworkPlan(@PathVariable String planCode){
        return csFramePlanService.allowFrameworkPlan(planCode);
    }

    /**
     * 获得供应商列表
     */
    @GetMapping("/getSupplierList")
    public R<List<CSSupplierVO>> getSupplierList(){
        return csFramePlanService.getSupplierList();
    }
    /**
     * 驳回框架计划
     */
    @RequiresLogin
    @PutMapping("/rejectFrameworkPlan/{planCode}")
    public R<Integer> rejectFrameworkPlan(@PathVariable String planCode){
       return csFramePlanService.rejectFrameworkPlan(planCode);
    }

    /**
     * 删除框架计划
     */
    @RequiresLogin
    @DeleteMapping("/deleteFrameworkPlan/{planCode}")
    public R<Integer> deleteFrameworkPlan(@PathVariable String planCode){
        return csFramePlanService.deleteFrameworkPlan(planCode);
    }


    /**
     * 查询框架计划总数量
     * @return
     */
    @RequiresLogin
    @PostMapping("/selectFramePlanCount")
    public R selectFramePlanCount() {
        return R.ok(csFramePlanService.selectFramePlanCount());
    }
}
